1. Field of the Invention
The present invention relates generally to a time interpolation system and method and, more particularly, to a self-tuning time interpolation system and method.
2. Description of the Related Art
Computer operating systems employ timer interrupts as a way to track system time. In Linux operating systems, system time is incremented in intervals of around 1 millisecond (ms) by timer interrupts. The exact timing of when the timer interrupt is executed, however, may fluctuate due to interrupts being disabled or other hardware contingencies.
When interpolating the time in the time interval between two timer interrupts, these fluctuations need to be accounted for. Otherwise, time cannot be accurately determined. In the time interpolation method by David Mosberger, the difference between the actual time interval and the expected time interval is quantified and used as an offset that is to be applied in interpolating the time in a subsequent time interval. FIG. 1 illustrates this offset. The actual time interval is calculated with reference to the real-time clock (RTC) counter of the computer. In particular, it is calculated as the difference in the number of counts at the beginning and end of the time interval, multiplied by a scaling factor corresponding to the speed of the RTC. The expected time interval is typically 1 ms.
This offset is applied when determining the time in a subsequent time interval using the following formula:Time=xtime at beginning of subsequent time interval+(current RTC counter value−RTC counter value at beginning of subsequent time interval)*scaling factor+offset,where xtime is the absolute time measured in nanoseconds relative to Jan. 1, 1970, that is incremented by the expected time interval at every timer interrupt.
The offset value is updated at the end of each interval. It is increased in cases where the estimated timer interrupt occurs later than expected, and decreased in cases where the estimated timer interrupt occurs earlier than expected. When the offset value becomes less than zero, it cannot be used in any subsequent time calculation because it would result in a backwards movement of time and cause time to be passed again. As a result, it is set to zero, causing time to be skipped. For real-time applications, this is undesirable.